<?php

namespace html\core;

class attribute extends \system\core\abstractAttribute
{

	function __construct($keyvaluepair, $delimiter=false)
	{
		$pair = explode("=", $keyvaluepair, 2);
		$pair[0] = trim($pair[0]);
		$pair[1] = trim(@$pair[1]);

		if( $delimiter == false && $pair[1] == false )
		{
			$pair[1] = $pair[0];
		}
		elseif( $delimiter == false && $pair[1] != false )
		{

		}
		elseif( $delimiter )
		{
			$pair[1] = trim($pair[1]);
			if( $pair[1][0] === $delimiter && $pair[1][strlen($pair[1]) - 1] === $delimiter )
			{
				$pair[1] = substr($pair[1], 1, -1);
			}
		}
		else
		{
			throw new Exception("Error parsing attribute");
		}

		$this->setKey($pair[0]);
		$this->setValue($pair[1]);
		$this->setDelimiter($delimiter);
		$this->setSeparator("=");

//		$pair[0] = mb_convert_case($pair[0], $this->case_transform);
//		list($this->key, $this->val) = $pair;
//		$this->delimiter = $delimiter;
		return $this;
	}

}

?>
